import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';

import '../model/home_mo.dart';
import '../model/local_data.dart';
import '../navigator/hi_navigator.dart';

class HiBanner extends StatelessWidget {
  final List<BannerMo> bannerList;
  final double bannerHeight;
  final EdgeInsetsGeometry? padding;

  const HiBanner({super.key, required this.bannerList, this.bannerHeight = 160, this.padding});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: bannerHeight,
      child: _banner(),
    );
  }

  _banner() {
    return Swiper(
        autoplay: true,
        //自定义指示器
        pagination: const SwiperPagination(
            alignment: Alignment.bottomRight,
            margin: EdgeInsets.only(right: 10, bottom: 10),
            builder: DotSwiperPaginationBuilder(color: Colors.white60, size: 6, activeSize: 6)),
        itemBuilder: (BuildContext context, int index) {
          return _image(bannerList[index]);
        },
        itemCount: bannerList.length);
  }

  _image(BannerMo banner) {
    return InkWell(
      onTap: () {
        if (banner.type == 'video') {
          HiNavigator.getInstance.onJumpTo(RouteStatus.detail, args: {'videoModel': getVideo()});
        } else {
          print('type:${banner.type} ,url:${banner.url}');
          //todo
        }
      },
      child: Container(
          padding: padding,
          child: ClipRRect(
            borderRadius: const BorderRadius.all(Radius.circular(6)),
            child: Image.network(banner.cover, fit: BoxFit.cover),
          )),
    );
  }
}
